﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SilverlightGolf.Core;
using SilverlightGolf.Physics;
using System.ComponentModel;
using System.Windows.Media.Imaging;
using SilverlightGolf.Game;

namespace SilverlightGolf.Client
{
    public partial class GolfBall : UserControl, IDrawable
    {
        public Ball Ball { get; set; }

        private double radius;
        public double Radius
        {
            get
            {
                return radius;
            }
            set
            {
                radius = value;
                BallEllipse.Height = 2 * radius;
                BallEllipse.Width = 2 * radius;
            }
        }

        public Color Color
        {
            get { return MainGradientStop.Color; }
            set { MainGradientStop.Color = value; }
        }

        public GolfBall(Ball ball)
        {
            InitializeComponent();

            Radius = 7.5;
            Ball = ball;
            Ball.Show = new Action(() => this.Visibility = Visibility.Visible);
            Ball.Hide = new Action(() => this.Visibility = Visibility.Collapsed);
            this.Color = ball.Color;
        }

        public void Draw()
        {
            this.SetValue(Canvas.LeftProperty, Ball.Geom.Body.Position.X);
            this.SetValue(Canvas.TopProperty, Ball.Geom.Body.Position.Y);
        }
    }
}
